﻿using System;
using System.ComponentModel;
using SpectrumAnalyser.ModelObjects;

namespace SpectrumAnalyser.Shell.ViewModels
{
    [Serializable]
    public class SpectrumDbConnectionViewModel: SpectrumDbConnection, INotifyPropertyChanged
    {
        private bool _isUsed;

        public SpectrumDbConnectionViewModel()
        {
            
        }

        public SpectrumDbConnectionViewModel(SpectrumDbConnection dbConnection)
        {
            base.ConnectionName = dbConnection.ConnectionName;
            base.ConnectionString = dbConnection.ConnectionString;
            this.IsUsed = dbConnection.IsUsed;
        }

        public override bool IsUsed
        {
            get { return _isUsed; }
            set
            {
                _isUsed = value;
                OnPropertyChanged("IsUsed");
            }
        }

        //public abstract SpectrumDbConnection ToSpectrumDbConnection();

        //public abstract SpectrumDbConnectionViewModel FromSpectrumDbConnection(SpectrumDbConnection connection);

        public SpectrumDbConnection ToSpectrumDbConnection()
        {
            return new SpectrumDbConnection
                {
                    ConnectionName = this.ConnectionName,
                    ConnectionString = this.ConnectionString,
                    IsUsed = this.IsUsed,
                    Type = this.Type
                };
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}